package com.xyh.flowershop.enums;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 小约翰可汗
 * @className LoginEnum
 * @createTime 2024/7/1121:11
 */
public enum LoginEnum {

    ACCOUNT_LOGIN(1),
    EMAIL_LOGIN(2),
    WX_LOGIN(3);

    private Integer code;

    private static final Map<Integer, LoginEnum> loginTypeMap = new ConcurrentHashMap<>();

    static {
        for(LoginEnum loginEnum : LoginEnum.values()){
            loginTypeMap.put(loginEnum.code, loginEnum);
        }
    }

    public static LoginEnum fromLoginType(Integer code) {
        LoginEnum loginEnum = loginTypeMap.get(code);
        if(Objects.isNull(loginEnum)){
            loginEnum = loginEnum.ACCOUNT_LOGIN;
        }
        return loginEnum;
    }

    LoginEnum(Integer code) {
        this.code = code;
    }

    public Integer getCode() {
        return code;
    }
}
